<template>
  <page-main>
    <template #right>
      <el-button type="primary" icon="plus" @click="handleOperate(refAddEdit,{},'add')">新增</el-button>
      <!-- <el-button type="danger" icon="delete" @click="handleDelete(tableData.checkedIds)">批量删除</el-button> -->
      <!-- <el-button type="default" icon="download" @click="handleExport('参数','/api/admin/param/export', {})">导出</el-button> -->
    </template>
    <search-form ref="refSearchForm" @confirm="handleSearch" />
    <el-table
          v-loading="tableData.loading"
          ref="refTable"
          :data="tableData.list"
          stripe
          border
          style="width: 100%"
          row-key="id"
          :header-cell-style="tableData.headerCellStyle"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @selection-change="selectCheckbox"
          >
          <el-table-column label="ID" prop="bannerId"/>
          <el-table-column label="类型">
            <template #default="scope">
              <el-tag size="small">{{proxy.$util.selectName(scope.row.type, optionData.activitieMethod)}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="链接" prop="href"/>
          <el-table-column label="图片" prop="registrationTime">
            <template #default="scope">
						<div style="display: flex; justify-content: center">
							<ImageUpload v-model:imageUrl="scope.row.imgUrl" height="50px" width="50px" disabled />
						</div>
					</template>
          </el-table-column>
          <el-table-column label="排序" prop="top" />
          <el-table-column label="备注" prop="activitiesName" />
          <el-table-column label="是否开启" prop="role">
            <template #default="scope">
              <el-tag size="small">{{proxy.$util.selectName(scope.row.isStart, optionData.yesnoType)}}</el-tag>
            </template>
          </el-table-column>
          <!-- <el-table-column label="创建时间" prop="createTime"/> -->
          <el-table-column label="操作" fixed="right" width="240" align="center">
            <template #default="scope">
              <el-button
                size="small"
                type="primary"
                text
                @click="handleOperate(refAddEdit,scope.row,'edit')"
              >编辑</el-button>
              <el-button
                size="small"
                type="danger"
                text
                @click="handleDeleteMultiple([scope.row.bannerId])"
              >删除</el-button> 
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="pageData.current"
          :page-size="pageData.size"
          :page-sizes="pageData.pageSizes"
          :total="pageData.total"
          background
          style="padding: 30px 0; text-align: center;"
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="getList"
          @size-change="sizeChange"
        />
        <add-edit ref="refAddEdit" name="轮播图" @confirm="getList(dlgAddEdit.type == 'add'? 1 : pageData.current)"></add-edit> 
        <show-detail ref="refShowDetail" />
  </page-main>
</template>

<script setup lang="ts">
// import {onMounted, ref, reactive, provide,defineAsyncComponent, getCurrentInstance, ComponentInternalInstance} from 'vue';
let obj = {
  pageApi: '/admin/banner/page',
  deleteApi: '/admin/banner',
  primaryKey: 'bannerId',
  searchFixed:{},
}
import { useList } from '/@/assets/compositionFn/list';
let { dlgAddEdit, tableData, pageData, optionDataStore, getList, handleSearch, sizeChange, selectCheckbox, setDefaultCheckbox, handleOperate, handleDelete, handleDeleteMultiple, handleExport } = useList(obj);
const SearchForm = defineAsyncComponent(() => import('./components/SearchForm.vue'));
const AddEdit = defineAsyncComponent(() => import('./components/AddEdit.vue'));
const ShowDetail = defineAsyncComponent(() => import('./components/ShowDetail.vue'));
const ImageUpload = defineAsyncComponent(() => import('/@/components/Upload/Image.vue'));
const {proxy} :any = getCurrentInstance() as ComponentInternalInstance;
const refSearchForm = ref();
const refTable = ref();
const refAddEdit = ref();
const refShowDetail = ref();
const optionData:any = reactive({});

provide('optionData', optionData);
const getInitData = async ()=>{
  optionData.yesnoType = await optionDataStore.getDictList('yes_no_type');
  optionData.activitieMethod = await optionDataStore.getDictList('activitie_method');

};
const getRoleName = (role) => {
  let roles = role.split(':');
  let roleNames = roles.map(item => {
    let name = proxy.$util.setName(item, optionData.activityRole);
    return name;
  });
  return roleNames.join(',');
}
onMounted(async () => {
  await getInitData();
  getList()
  
})
</script>

<style>

</style>